function resetAndFlip(motor)
  speed = speedReading(motor)
  resetRotationCount(motor)
  forward(motor, -speed)
end

repeat
  light = activeLightReading(3)
  if light > 37 then
    forward(A)
    forward(B)
  else 
    forward(A)
    backward(B)
    repeat until activeLightReading(3) < 37 or abs(rotationCounts(A)) > 10
    resetAndFlip(A)
    resetAndFlip(B)
    repeat until activeLightReading(3) < 37 or abs(rotationCounts(A)) > 20  
  end
until isPressed(ESCAPE)

